package com.wyd.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RefreshScope
public class ProviderController {

    @Value("${server.port}")
    private String port;

    @Value("${config.version}")
    private String version;

    @GetMapping("/provider/getPort")
    public String getPort() {
        String result = String.format(">>当前端口号：%s,version:%s", port,version);
        log.info(result);
        return result;
    }

    @GetMapping("/provider/getRandomLog")
    public String getRandomLog() {
        Double random = Math.random();
        log.info(">>random：{}", random);
        return String.valueOf(random);
    }


    @GetMapping("/provider/getRandom")
    public String getRandom() {
        Double random = Math.random();
        return String.valueOf(random);
    }

    @GetMapping("/provider/getSleep")
    public String getSleep(@RequestParam(value="time",required=false,defaultValue="50") Integer time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "OK";
    }

}
